package com.vcg;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 自定义解码器
 */
public class SharedWashingMachineHeathDecode extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        byte[] bytes = new byte[in.readableBytes()];
        in.readBytes(bytes);
        out.add(new String(bytes));
        //由于java 不支持无符号位 byte 类型 故用short 表示
//        short headFrame = in.readUnsignedByte();
//        System.err.println(headFrame);
        //        System.err.println(s);
//        byte dataLength = in.readByte();
//        byte[] moduleNumber = new byte[9];
//        in.readBytes(moduleNumber);
//        byte productCode = in.readByte();
//        byte itemCode = in.readByte();
//        byte replayCommand = in.readByte();
//        byte crc = in.readByte();
//        byte[] replayArgs = new byte[9];
//        byte[] crcValidate = new byte[2];
    }
}
